import { defineComponent, ref } from 'vue'
import { NCol, NForm, NFormItem, NInput, NRow, useMessage } from 'naive-ui'
import { useRouter } from 'vue-router'
import { getAssetsInfo } from '@/service/modules/integration-assets'

const infoHandle = defineComponent({
  name: 'infoHandle',
  setup() {
    const infoForm = ref({
      tableName: '',
      schemaName: '',
      colNameJson: '',
      sourceTableJson: '',
      partitionColNameJson: '',
      tableFsOwner: '',
      tableParametersJson: '',
      tableInputFormat: '',
      tableOutputFormat: '',
      tableRowFormatSerde: '',
      tableCreateTime: '',
      tableType: '',
      tableBucketColsJson: '',
      tableBucketNum: '',
      tableSortColsJson: '',
      tableSize: '',
      tableLastModifyTime: '',
      tableLastModifyPath: '',
      tableLastModifySize: '',
      fsCapcitySize: '',
      fsUsedSize: '',
      fsRemainSize: '',
      tecOwnerUserId: '',
      busiOwnerUserId: '',
      deptId: '',
      lifecycleDays: '',
      securityLevel: '',
      dwLevel: '',
      createTime: ''
    })

    const router = useRouter()

    const getInfo = function () {
      // @ts-ignore
      getAssetsInfo(router.currentRoute.value.query.tableName)
        .then((res: any) => {
          infoForm.value = res.data
        })
        .catch((err: any) => {
          message.error(err.msg ? err.msg : '接口未知错误')
        })
    }

    const message = useMessage()

    getInfo()

    return {
      infoForm,
      router,
      getInfo,
      message
    }
  },
  render() {
    return (
      <NForm model={this.infoForm} label-placement='left'>
        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='表名' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableName}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='库名' label-width='160'>
              <NInput
                v-model:value={this.infoForm.schemaName}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='字段名json' label-width='160'>
              <NInput
                v-model:value={this.infoForm.colNameJson}
                placeholder=''
                type={'textarea'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='上游表名json' label-width='160'>
              <NInput
                v-model:value={this.infoForm.sourceTableJson}
                placeholder=''
                type={'textarea'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='分区字段名' label-width='160'>
              <NInput
                v-model:value={this.infoForm.partitionColNameJson}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='hdfs所属人' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableFsOwner}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='参数信息' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableParametersJson}
                placeholder=''
                type={'textarea'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='输入格式' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableInputFormat}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='输出格式' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableOutputFormat}
                placeholder=''
                type={'textarea'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='行格式' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableRowFormatSerde}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='hdfs路径' label-width='160'>
              <NInput
                v-model:value={this.infoForm.partitionColNameJson}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='表创建时间' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableCreateTime}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='表类型' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableType}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='分桶列' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableBucketColsJson}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='分桶个数' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableBucketNum}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='排序列' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableSortColsJson}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='数据量大小' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableSize}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='最后修改时间' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableLastModifyTime}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='最后修改路径' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tableLastModifyPath}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem
              path='tableName'
              label='最后修改路径大小'
              label-width='160'
            >
              <NInput
                v-model:value={this.infoForm.tableLastModifySize}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem
              path='tableName'
              label='当前文件系统容量'
              label-width='160'
            >
              <NInput
                v-model:value={this.infoForm.fsCapcitySize}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem
              path='tableName'
              label='当前文件系统使用量'
              label-width='160'
            >
              <NInput
                v-model:value={this.infoForm.fsUsedSize}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem
              path='tableName'
              label='当前文件系统剩余量'
              label-width='160'
            >
              <NInput
                v-model:value={this.infoForm.fsRemainSize}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='技术负责人' label-width='160'>
              <NInput
                v-model:value={this.infoForm.tecOwnerUserId}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='业务负责人' label-width='160'>
              <NInput
                v-model:value={this.infoForm.busiOwnerUserId}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='负责部门' label-width='160'>
              <NInput
                v-model:value={this.infoForm.deptId}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='生命周期' label-width='160'>
              <NInput
                v-model:value={this.infoForm.lifecycleDays}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='安全级别' label-width='160'>
              <NInput
                v-model:value={this.infoForm.securityLevel}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>

        <NRow>
          <NCol span={11}>
            <NFormItem path='tableName' label='数仓所在层级' label-width='160'>
              <NInput
                v-model:value={this.infoForm.dwLevel}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
          <NCol span={11}>
            <NFormItem path='tableName' label='创建时间' label-width='160'>
              <NInput
                v-model:value={this.infoForm.createTime}
                placeholder=''
                type={'text'}
              ></NInput>
            </NFormItem>
          </NCol>
        </NRow>
      </NForm>
    )
  }
})

export default infoHandle
